package playn.game.level;

import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.World;

import playn.core.GroupLayer;
import playn.core.SurfaceLayer;
import playn.game.core.Camera;
import playn.game.core.Game;
import playn.game.core.StaticRenderer;
import tiled.simple.core.Map;
import static playn.core.PlayN.*;

public class Level {
	public static final float PIXEL_PER_METER=500;

	public GroupLayer layer;
	private Camera camera;

	
	public Level(){
		layer=graphics().createGroupLayer();
		layer.setVisible(false);
	}

	public static World world;
	
	public void start(int levelNumber){
		layer.clear();
		Map map=Game.maps.get("Level1.tmx");

		int w=map.getWidth()*map.getTileWidth();
		int h=map.getHeight()*map.getTileHeight();
		SurfaceLayer staticLayer=graphics().createSurfaceLayer(w,h);
		
		
		boolean doSleep = true;
		Vec2 gravity = new Vec2(0.0f, 0.0f);
		world = new World(gravity,doSleep);
		JBox2dDebugger debugger=new JBox2dDebugger(w,h);
		
		
		layer.add(staticLayer);
		layer.add(debugger.layer);
		
		
		map.render(new StaticRenderer(staticLayer));
		camera=new Camera(staticLayer);
		layer.setVisible(true);
		layer.setAlpha(0);
		a=0;
		

	}
	
	float a;
	public void update(float delta){
		a+=0.01f;
		camera.setPosition( (float)(300+100*Math.sin(a)),(float)(300+100*Math.cos(a)));
		
		camera.update();
	}
	
}
